﻿using System;

class MaxSequence
{
    static void Main()
    {
        //Exercise 4.
        //Write a program that finds the maximal sequence of equal elements in an array.
		//Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1} -> {2, 2, 2}.

        //enter the length and the elements of the array from the console
        Console.Write("Type the length of the array:  ");
        int length = int.Parse(Console.ReadLine());
        Console.WriteLine("Type the elements of the array:");
        int[] array = new int[length];
        for (int i = 0; i < length; i++)
        {
            array[i] = int.Parse(Console.ReadLine());
        }

        int sequenceLength = 1;
        int bestNumber = 0;
        int bestSequenceLength = 0;

        for (int i = 0; i < length - 1; i++)
        {
            if (array[i] == array[i + 1])
            {
                sequenceLength++;           //if the two elements are equal, the counter in increased
                    
                if (sequenceLength > bestSequenceLength)
                {
                    bestSequenceLength = sequenceLength;
                    bestNumber = array[i];
                }
            }
            else
            {
                sequenceLength = 1;          //else the counter is set at its starting point          
            }                
        }
        Console.WriteLine();
            
        Console.Write("The maximal sequence ({0}) of equal elements in the array is: ", bestSequenceLength);
        for (int i = 0; i < bestSequenceLength; i++)
        {
            Console.Write("{0} ", bestNumber);
        }
        Console.WriteLine();
    }
}

